package com.arpa.wms.domain.enums;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.enums.IEnum;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: rfwang
 * @Date 2021/7/1
 * @Description:
 */
public enum BillingMethodEnum implements IEnum<String> {
    /**
     * 计费方式
     */
    DAYS("days","天"),
    HOURS("hours","工时"),
    PIECES("pieces","件");
    /**
     * 值
     */
    private String value;

    /**
     * 描述
     */
    private String desc;

    public static BillingMethodEnum catchMessage(String msg) {
        BillingMethodEnum result = null;
        for (BillingMethodEnum s : values()) {
            if (s.getDesc().equals(msg)) {
                result = s;
                break;
            }
        }
        return result;
    }


    BillingMethodEnum(String value, String desc) {
        this.value = value;
        this.desc = desc;
    }

    public static String translate(String value){
        BillingMethodEnum item = ENUM_MAP.get(value);
        if(item != null){
            return item.getDesc();
        }
        return StrUtil.EMPTY;
    }

    private static final Map<String, BillingMethodEnum> ENUM_MAP = new HashMap();

    static {
        for(BillingMethodEnum item: values()){
            ENUM_MAP.put(item.getValue(), item);
        }

    }

    public static BillingMethodEnum getEnumByValue(String value) {
        return ENUM_MAP.get(value);
    }

    @Override
    public String getValue() {
        return value;
    }

    @Override
    public String toString(){
        return this.desc;
    }

    public String getDesc() {
        return desc;
    }

}
